#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include<Windows.h>
#define N 200
int quick_sort(int *a, int low, int high)
{
	int i = low;	//????
	int j = high;	//?????
	int key = a[i]; //????????????????-- ????????????
 
	while (i < j)
	{					
		while(i < j && a[j] >= key)
		{
			j--;
		}
		a[i] = a[j];	
 
		while(i < j && a[i] <= key)
		{
			i++;
		}
		a[j] = a[i];
	}
	a[i] = key;
	if (i-1 > low) 
	{
		quick_sort(a, low, i-1);
	}
 
	if (i+1 < high)
	{
		quick_sort(a, i+1, high);
	}
 
	return 0;
} 
 
//????????
int main() {
    int a[N];
     FILE *fp;  
    int i;  
    fp = fopen("data1.dat", "w");  
    if (!fp) {  
        perror("Failed to open file for writing integers");  
        return EXIT_FAILURE;  
    }  
    for (i = 0; i < 100; i++) {
        srand((unsigned)time(NULL));a[i] = rand();
        fwrite(&a[i] , sizeof(int), 1, fp);  Sleep(1);
    }  
    fclose(fp);  
fp = fopen("data2.dat", "w");  
    if (!fp) {  
        perror("Failed to open file for writing integers");  
        return EXIT_FAILURE;  
    }  
    for (i = 0; i < 100; i++) {
        srand((unsigned)time(NULL));a[i+100] = rand();
        fwrite(&a[i+100], sizeof(int), 1, fp);  Sleep(1);
    }  
    fclose(fp); 
     i = 0;
	printf("??????:a??\n");
	for(i = 0; i < 100; i++)
	{
		printf("%d ", a[i]);
	}
	putchar(10);//????
 	printf("???????:b??\n");
	for(i = 100; i < 200; i++)
	{
		printf("%d ", a[i]);
	}
    putchar(10);//????
	//????-????
	quick_sort(a, 0, N-1);//????0 ??9
	
	printf("???????:\n");
	for(i = 0; i < N; i++)
	{
		printf("%d ", a[i]);
	}
	putchar(10);

    return 0;

}